package com.xtj.direct;


import com.rabbitmq.client.*;
import com.xtj.utils.RabbitMQUtils;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

public class Customer1 {
    //消费对象
    public static void main(String[] args) throws IOException, TimeoutException {
       //获取连接对象
        Connection connection = RabbitMQUtils.getConnection();
        //获取连接中通道
        Channel channel = connection.createChannel();
        //交换机到绑定交换机和队列
        channel.exchangeDeclare("logs_direct","direct");
        //临时队列
        String queuName = channel.queueDeclare().getQueue();
        //临时队列绑定交换机和队列
        channel.queueBind(queuName,"logs_direct","info");
        channel.queueBind(queuName,"logs_direct","error");
        channel.queueBind(queuName,"logs_direct","warning");
        //消费信息
        channel.basicConsume(queuName,true,new DefaultConsumer(channel){
            @Override
            public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body) throws IOException {
                System.out.println("消费者2:"+new String(body));
            }
        });



}
}
